program eva;
const n=8;
var a:array[1..n] of word;

procedure output(site:word); {Print a line}
var i:integer;
begin
  for i:=1 to n do
    begin
      if i=site then
        write('Q':2);
      write('*':2);
    end;
  writeln;
end;
function pass(m,site:integer):boolean;
var p:boolean;
    i:integer;
begin
  p:=true;
  for i:=m-1 downto 1 do
    begin
      if (a[i]=site)or(a[i]=site-abs(m-i))or(a[i]=site+abs(m-i)) then
        begin
          p:=false;
          break;
        end;
    end;
  pass:=p;
end;

procedure main;
var site,i,d:integer;
begin
  d:=0;
  site:=1;
  while site>0 do
    begin
      if site>n then {the bottom}
        begin
          inc(d);
          writeln('No.',d);
          for i:=1 to n do
              output(a[i]);;
          readln;
          dec(site);
        end
      else
        begin
          inc(a[site]);
          while not pass(site,a[site]) do
            inc(a[site]);
          if a[site]>n then
             begin
               dec(site);
             end
           else
             begin
               inc(site);
               a[site]:=0;
             end;
        end;
    end;
  writeln(d);
end;

begin
 fillchar(a,sizeof(a),0);
 main;
end.
